﻿using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using Common.Dto;
using Common;


namespace DataAccess.DataHelper
{
    public class GetDataHelper
    {
        public GetDataHelper()
        {

        }

        public List<CutPartsBankInOrOutDto> GetCutPartsBankInOrOut(int actionTypeId)
        {
            List<CutPartsBankInOrOutDto> result;

            using (var context = new liangshuaiEntities())
            {
                var masterRecordList = context.masterrecord;
                var bankInOutList = context.bankinout;
                var colorList = context.color;
                var sizeList = context.size;
                var actionTypeList = context.actiontype;

                result = (from masRec in masterRecordList
                          join col in colorList on masRec.Color_ID equals col.ID
                          join si in sizeList on masRec.Size_ID equals si.ID
                          join bkInOut in bankInOutList on masRec.ID equals bkInOut.MasterRecord_ID
                          join actType in actionTypeList on masRec.ActionType_ID equals actType.ID
                          where actType.ID == actionTypeId
                          select new CutPartsBankInOrOutDto
                          {
                              OrderId = masRec.OrderID,
                              Color = col.ColorName,
                              Size = si.SizeName,
                              PlanNum = masRec.PlanNum,
                              BankInOutNum =  bkInOut.Num,
                              Operator = bkInOut.Operator,
                              BankInDate = bkInOut.Date,
                              Operatee = bkInOut.Operatee,
                              BankOutDate = bkInOut.Date
                          }).ToList();
            }

            return result;
        }

        public List<ColorDto> GetColorList()
        {
            List<ColorDto> result;

            using (var context = new liangshuaiEntities())
            {
                var colorList = context.color;

                result = (from col in colorList
                          select new ColorDto()
                          {
                              ID = col.ID,
                              ColorName = col.ColorName
                          }).ToList();
            }

            return result;
        }

        public List<ProviderDto> GetProviderList()
        {
            List<ProviderDto> result;

            using (var context = new liangshuaiEntities())
            {
                var providerList = context.provider;

                result = (from pro in providerList
                          select new ProviderDto()
                          {
                              ID = pro.ID,
                              ProviderName = pro.ProviderName
                          }).ToList();
            }

            return result;
        }

        public List<ProductDto> GeProdectNameList()
        {
            List<ProductDto> result;

            using (var context = new liangshuaiEntities())
            {
                var productList = context.product;

                result = (from pro in productList
                          select new ProductDto()
                          {
                              ID = pro.ID,
                              ProdectName = pro.ProductName
                          }).ToList();
            }

            return result;
        }

        public List<SizeDto> GeSizeList()
        {
            List<SizeDto> result;

            using (var context = new liangshuaiEntities())
            {
                var SizeList = context.size;

                result = (from si in SizeList
                          select new SizeDto()
                          {
                              ID = si.ID,
                              SizeName = si.SizeName
                          }).ToList();
            }

            return result;
        }

        public List<StyleDto> GeStyleList()
        {
            List<StyleDto> result;

            using (var context = new liangshuaiEntities())
            {
                var styleList = context.style;

                result = (from sty in styleList
                          select new StyleDto()
                          {
                              ID = sty.ID,
                              StyleNum = sty.StyleNum
                          }).ToList();
            }

            return result;
        }

        public List<ActionTypeDto> GetActionType()
        {
            List<ActionTypeDto> result;

            using (var context = new liangshuaiEntities())
            {
                var actionTypeList = context.actiontype;

                result = (from act in actionTypeList
                          select new ActionTypeDto()
                          {
                              ID = act.ID,
                              ActionTypeName = act.ActionTypeName
                          }).ToList();
            }

            return result;
        }
    }
}
